package org.mil.bean.dom;

import java.util.Arrays;

public class H264ConfigInfoDO extends GenericDocumentObject {
	protected String cabac;
	protected String ref;
	protected String subme;
	protected String bframes;
	protected String me; // [u]umh,[h]hex
	protected String rc; // [c]crf,[2]2pass
	protected String crf;
	protected String keyint;
	protected String keyint_min;
	protected String bitrate;

	public String getCabac() {
		return cabac;
	}

	public String getRef() {
		return ref;
	}

	public String getSubme() {
		return subme;
	}

	public String getBframes() {
		return bframes;
	}

	public String getMe() {
		return me;
	}

	public String getRc() {
		return rc;
	}

	public String getCrf() {
		return crf;
	}

	public String getKeyint() {
		return keyint;
	}

	public String getKeyint_min() {
		return keyint_min;
	}

	public String getBitrate() {
		return bitrate;
	}

	public static H264ConfigInfoDO newInstance(String source) {
		H264ConfigInfoDO cido = new H264ConfigInfoDO();
		cido.read(source);
		return cido;
	}

	public void read(String source) {
		String[] exps = source.split("/");
		for (String f : this.getFieldNames()) {
			int x;
			for (String exp : exps) {
				if (exp.contains(f) && exp.trim().charAt(f.length() ) == '=') {
					 x = exp.indexOf('=');
					set(f, exp.substring(x + 1).trim());
					break;
				}

			}
		}

	}

	public static void main(String[] arg) {
		String S = " cabac=1 / ref=10 / deblock=1:-1:-1 / analyse=0x3:0x113 / me=umh / subme=9 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=1 / me_range=16 / chroma_me=1 / trellis=2 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=-2 / threads=3 / sliced_threads=0 / nr=0 / decimate=1 / mbaff=0 / interlaced=0 / constrained_intra=0 / bframes=8 / b_pyramid=0 / b_adapt=2 / b_bias=0 / direct=3 / wpredb=1 / wpredp=2 / keyint=250 / keyint_min=25 / scenecut=40 / intra_refresh=0 / rc_lookahead=40 / rc=2pass / mbtree=1 / bitrate=980 / ratetol=1.0 / qcomp=0.60 / qpmin=10 / qpmax=51 / qpstep=4 / cplxblur=20.0 / qblur=0.5 / ip_ratio=1.40 / aq=1:1.00 / pulldown=0";
		H264ConfigInfoDO h = new H264ConfigInfoDO();
		h.read(S);
		System.out.println(Arrays.toString(h.getFieldNames()));
		System.out.println(Arrays.toString(h.getFieldValues()));
	}
}
